<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生微信" prop="weixin">
        <el-input
          v-model="queryParams.weixin"
          placeholder="请输入学生微信"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入学生电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预约时间" prop="orderTime">
        <el-date-picker clearable
          v-model="queryParams.orderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="所在班级" prop="classes">
        <el-input
          v-model="queryParams.classes"
          placeholder="请输入所在班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题类型" prop="questionType">
        <el-select v-model="queryParams.questionType" placeholder="请选择问题类型" clearable>
          <el-option
            v-for="dict in dict.type.question_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="帮扶状态" prop="helpStates">
        <el-select v-model="queryParams.helpStates" placeholder="请选择帮扶状态" clearable>
          <el-option
            v-for="dict in dict.type.help_states"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="帮扶老师" prop="teacherId">
        <el-input
          v-model="queryParams.teacherId"
          placeholder="请输入帮扶老师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生姓名" prop="stuName">
        <el-input
          v-model="queryParams.stuName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="老师备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入老师备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="完成时间" prop="finishTime">
        <el-date-picker clearable
          v-model="queryParams.finishTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择完成时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['obtain:help:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['obtain:help:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['obtain:help:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['obtain:help:export']"
        >导出</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleTransfer"
          v-hasPermi="['obtain:help:transfer']"
        >移交他人</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="helpList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="学生微信" align="center" prop="weixin" />
      <el-table-column label="学生电话" align="center" prop="phone" />
      <el-table-column label="预约时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所在班级" align="center" prop="classes" />
      <el-table-column label="问题类型" align="center" prop="questionType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.question_type" :value="scope.row.questionType"/>
        </template>
      </el-table-column>
      <el-table-column label="帮扶状态" align="center" prop="helpStates">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.help_states" :value="scope.row.helpStates"/>
        </template>
      </el-table-column>
      <el-table-column label="问题描述" align="center" prop="questionDes" />
      <el-table-column label="帮扶老师" align="center" prop="teacherName" />
      <el-table-column label="学生姓名" align="center" prop="stuName" />
      <!--<el-table-column label="老师备注" align="center" prop="remarks" />
      <el-table-column label="完成时间" align="center" prop="finishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['obtain:help:edit']"
          >老师帮扶</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-custom"
            @click="handleValuationAdd(scope.row)"
            v-hasPermi="['help:help:add']"
          >帮扶评价</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['obtain:help:edit']"
          >修改</el-button>-->

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['obtain:help:remove']"
          >删除</el-button>


        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <!-- 添加或修改就业帮扶对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="formRules" label-width="80px">
        <el-form-item label="学生微信" prop="weixin">
          <el-input v-model="form.weixin" placeholder="请输入学生微信" />
        </el-form-item>
        <el-form-item label="学生姓名" prop="stuName">
          <el-input v-model="form.stuName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="学生电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入学生电话" />
        </el-form-item>
        <el-form-item label="预约时间" prop="orderTime">
          <el-date-picker clearable
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="所在班级" prop="classes">
          <el-input v-model="form.classes" placeholder="请输入所在班级" />
        </el-form-item>
        <el-form-item label="问题类型" prop="questionType">
          <el-select v-model="form.questionType" placeholder="请选择问题类型">
            <el-option
              v-for="dict in dict.type.question_type"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--<el-form-item label="帮扶状态" prop="helpStates">
          <el-select v-model="form.helpStates" placeholder="请选择帮扶状态">
            <el-option
              v-for="dict in dict.type.help_states"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="帮扶老师" prop="teacher">
          <el-select v-model="form.teacherId" placeholder="请选择">
            <el-option v-for="item in teacherList"
                       :label="item.name"
                       :value="item.id">
              <span style="float: left">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <!--<el-form-item label="帮扶老师" prop="teacherId">
          <el-input v-model="form.teacherId" placeholder="请输入帮扶老师" />
        </el-form-item>-->

        <!--<el-form-item label="老师备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入老师备注" />
        </el-form-item>
        <el-form-item label="完成时间" prop="finishTime">
          <el-date-picker clearable
            v-model="form.finishTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择完成时间">
          </el-date-picker>
        </el-form-item>-->
        <el-form-item label="问题描述" prop="questionDes">
          <el-input v-model="form.questionDes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!--老师处理帮扶-->
    <el-dialog :title="title"  :visible.sync="saveFormVisible" width="500px" :close-on-click-modal="false">
      <!--ref="saveForm" 指定表单名称，以后可以通过this.$refs.roleForm-->
      <el-form :model="updateForm" label-width="80px"  ref="saveForm">

        <el-form-item label="学生名字" prop="name"   >
          <el-input v-model="updateForm.stuName" :disabled="hibit"   placeholder="请输入学生名字" />
        </el-form-item>

        <el-form-item label="学生微信" prop="vx">
          <el-input v-model="updateForm.weixin" :disabled="hibit" placeholder="请输入学生微信" />
        </el-form-item>
        <el-form-item label="学生电话" prop="phone">
          <el-input v-model="updateForm.phone" :disabled="hibit" placeholder="请输入学生电话" />
        </el-form-item>
        <el-form-item label="预约时间"  prop="appointmenttime">
          <el-date-picker clearable :disabled="hibit"
                          v-model="updateForm.orderTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="所在班级"  prop="classes">
          <el-input v-model="updateForm.classes" :disabled="hibit" placeholder="请输入所在班级" />
        </el-form-item>
        <el-form-item label="帮扶类型" prop="problemtype">
          <el-select v-model="updateForm.helpStates" :disabled="hibit" placeholder="请选择帮扶类型">
            <el-option
              v-for="dict in dict.type.help_states"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>

        <!--<el-form-item label="帮扶老师" prop="teacherid">
          <el-input v-model="form.teacherid" placeholder="请输入帮扶老师" />
        </el-form-item>-->

        <el-form-item label="帮扶老师"  prop="teacher">
          <el-select v-model="updateForm.teacherId"  placeholder="请选择" >
            <el-option v-for="item in teacherList"
                       :label="item.name"
                       :value="item.id">
              <span style="float: left">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>

        <!--<el-form-item label="问题描述" prop="question">
          <el-input v-model="form.question" placeholder="请输入问题描述" />
        </el-form-item>-->

        <el-form-item label="问题描述" prop="question"  >
          <el-input type="textarea"  :rows="2" placeholder="请输入问题描述" :disabled="hibit" v-model="updateForm.questionDes">
          </el-input>
        </el-form-item>


        <el-form-item label="帮扶状态" prop="state">
          <el-select v-model="updateForm.helpStates" placeholder="请选择帮扶状态">
            <el-option
              v-for="dict in dict.type.help_states"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="老师备注" prop="question"  >
          <el-input type="textarea"  :rows="2" placeholder="请输入问题描述" v-model="updateForm.remarks">
          </el-input>
        </el-form-item>

        <el-form-item label="完成时间"  prop="appointmenttime">
          <el-date-picker clearable
                          v-model="updateForm.finishTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择预约时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateHelpForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 评价的模态框 -->
    <el-dialog :title="title" :visible.sync="valuationFormVisible" width="500px" append-to-body>
      <el-form ref="valuationForm" :model="valuationForm"   label-width="80px">


        <el-form-item label="帮扶老师"  prop="teacher">
          <el-select v-model="valuationForm.teacherId" :disabled="true" placeholder="请选择" >
            <el-option v-for="item in teacherList"
                       :label="item.name"
                       :value="item.id">
              <span style="float: left">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="得分" prop="score">
          <div class="block">
            <el-rate v-model="valuationForm.score"></el-rate>
          </div>
        </el-form-item>

        <el-form-item label="评价内容" prop="evaluate"  >
          <el-input type="textarea"  :rows="2" placeholder="请输入问题描述" v-model="valuationForm.content">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="valuationsubmitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 移交他人 -->
    <el-dialog :title="title" :visible.sync="transferFormVisible" width="500px" append-to-body>
      <el-form ref="transferForm" :model="transferForm"  :rules="rules"  label-width="80px">

        <el-form-item label="学生名字" prop="name"   >
          <el-input v-model="transferForm.stuName" :disabled="true"   placeholder="请输入学生名字" />
        </el-form-item>

        <el-form-item label="当前老师"  prop="teacher">
          <el-select v-model="transferForm.teacherId" :disabled="true" placeholder="请选择" >
            <el-option v-for="item in teacherList"
                       :label="item.name"
                       :value="item.id">
              <span style="float: left">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="移交老师"  prop="teacher">
          <el-select v-model="transferForm.newTeacherId"  placeholder="请选择" >
            <el-option v-for="item in teacherList"
                       :label="item.name"
                       :value="item.id">
              <span style="float: left">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="老师备注" prop="evaluate"  >
          <el-input type="textarea"  :rows="2" placeholder="请输入问题描述" v-model="transferForm.content">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="transfersubmitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listHelp, getHelp, delHelp, addHelp, updateHelp, addValuation,addTransfer } from "@/api/obtain/help";
import {listTeacher} from "@/api/obtain/teacher";
import request from "@/utils/request";

export default {
  name: "Help",
  dicts: ['question_type', 'help_states'],
  data() {
    return {
      //查询老师模型数据
      teacherList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //禁用单个表单数据
      hibit:true,
      // 总条数
      total: 0,
      // 就业帮扶表格数据
      helpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示修改弹出层
      saveFormVisible:false,
      // 是否显示评价弹出层
      valuationFormVisible:false,

      transferFormVisible:false,
      formRules: {
        weixin: [
          { required: true, message: '请输入微信', trigger: 'blur' }
        ],
        orderTime: [
          { required: true, message: '请输入预约时间', trigger: 'blur' }
        ],
        questionType: [
          { required: true, message: '请输入问题类型', trigger: 'blur' }
        ],
        helpStates: [
          { required: true, message: '请输入帮扶状态', trigger: 'blur' }
        ],
        questionDes: [
          { required: true, message: '请输入问题描述', trigger: 'blur' }
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        weixin: null,
        phone: null,
        orderTime: null,
        classes: null,
        questionType: null,
        helpStates: null,
        questionDes: null,
        teacherId: null,
        stuName: null,
        remarks: null,
        finishTime: null

      },
      // 表单参数
      form: {

      },
      updateForm:{},
      valuationForm:{},
      transferForm:{},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "学生名字不能为空", trigger: "blur" }
        ],
        appointmenttime: [
          { required: true, message: "预约时间不能为空", trigger: "blur" }
        ],
        problemtype: [
          { required: true, message: "帮扶类型不能为空", trigger: "change" }
        ],
        evaluate: [
          { required: true, message: "老师备注不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getTeacher();
  },
  methods: {
    /** 查询老师管理列表 */
    getTeacher() {
      this.loading = true;
      listTeacher(this.queryParams).then(response => {
        this.teacherList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询就业帮扶列表 */
    getList() {
      this.loading = true;
      listHelp(this.queryParams).then(response => {
        this.helpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.saveFormVisible=false;
      this.valuationFormVisible=false;
      this.transferFormVisible=false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        weixin: null,
        phone: null,
        orderTime: null,
        classes: null,
        questionType: null,
        helpStates: null,
        questionDes: null,
        teacherId: null,
        stuName: null,
        remarks: null,
        finishTime: null
      };
      this.resetForm("form");
      this.resetForm("updateForm");
    },

    resetValuation() {
      this.valuationForm = {
        id: null,
        completiontime: null,
        score: null,
        evaluate: null,

      };
      this.resetForm("valuationForm");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      81
      this.open = true;
      this.title = "添加就业帮扶";
    },
    /*老师帮扶操作*/
    handleUpdate(row) {
      this.reset();
      this.hibit= row.id!=null;
      const id = row.id || this.ids
      getHelp(id).then(response => {
        this.updateForm = response.data;
        this.saveFormVisible = true;
        this.title = "修改就业帮扶";
      });
    },
   /* handleHelp(row){
      this.reset();
      const id = row.id || this.ids
      getHelp(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就业帮扶";
      });
    },*/

    /** 移交他人按钮操作 */
    handleTransfer(row) {
      this.reset();
      this.hibit= row.id!=null;
      const id = row.id || this.ids
      getHelp(id).then(response => {
        this.transferForm = response.data;
        this.transferFormVisible = true;
        this.title = "移交他人就业帮扶";
      });
    },
    /** 点击帮扶评价*/
    handleValuationAdd(row){
      /*this.resetValuation();*/
      const id = row.id || this.ids
      getHelp(id).then(response => {
        this.valuationForm = response.data;
        this.valuationFormVisible = true;
        this.title = "添加就业评价";
      });

    },

    /** 帮扶评价提交按钮*/
    valuationsubmitForm(){
      addValuation(this.valuationForm).then(response => {
        this.$modal.msgSuccess("评价成功");
        this.valuationFormVisible = false;
        this.getList();
      })

    },
    /** 移交他人提交按钮*/
    transfersubmitForm(){
      addTransfer(this.transferForm).then(response => {
        this.$modal.msgSuccess("移交成功");
        this.transferFormVisible = false;
        this.getList();
      })
    },



    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHelp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHelp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 提交修改按钮 */
    updateHelpForm() {
      updateHelp(this.updateForm).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.saveFormVisible = false;
        this.getList();
      })
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除就业帮扶编号为"' + ids + '"的数据项？').then(function() {
        return delHelp(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('obtain/help/export', {
        ...this.queryParams
      }, `help_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
